﻿#nullable enable

using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PHMEE.Controllers;

namespace PHMEE.EnergyEfficiency;

/// <summary>
/// 碳强度（CII）管理
/// </summary>
[Route("api/cbm/cii")]
public class CIIController : PHMEEController, ICIIAppService
{
    private readonly ICIIAppService _ciiAppService;

    public CIIController(ICIIAppService ciiAppService)
    {
        _ciiAppService = ciiAppService;
    }

    /// <summary>
    /// 年度CII（未修正）
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="year"></param>
    /// <returns></returns>
    [Route("AnnualCIIUnadjusted")]
    [HttpGet]
    public Task<AnnualCIIDto> AnnualCIIUnadjusted(Guid vesselId,
        int? year)
    {
        return _ciiAppService.AnnualCIIUnadjusted(vesselId, year);
    }

    /// <summary>
    /// 年度 CII（已修正）
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="year"></param>
    /// <returns></returns>
    [Route("AnnualCIIAdjusted")]
    [HttpGet]
    public Task<AnnualCIIDto> AnnualCIIAdjusted(Guid vesselId,
        int? year)
    {
        return _ciiAppService.AnnualCIIAdjusted(vesselId, year);
    }

    /// <summary>
    /// 本航次 CII
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("CurrentVoyageCII")]
    [HttpGet]
    public Task<CIIWithGradeDto> CurrentVoyageCII(Guid vesselId)
    {
        return _ciiAppService.CurrentVoyageCII(vesselId);
    }

    /// <summary>
    /// 瞬时 CII
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("InstantaneityCII")]
    [HttpGet]
    public Task<CIIWithGradeDto> InstantaneityCII(Guid vesselId)
    {
        return _ciiAppService.InstantaneityCII(vesselId);
    }

    /// <summary>
    /// 本年度 CII 预测
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("CurrentYearCIIPrediction")]
    [HttpGet]
    public Task<CIIWithGradeDto> CurrentYearCIIPrediction(Guid vesselId)
    {
        return _ciiAppService.CurrentYearCIIPrediction(vesselId);
    }

    /// <summary>
    /// 本年度累计 CII
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("CurrentYearCumulativeCII")]
    [HttpGet]
    public Task<CIIWithGradeDto> CurrentYearCumulativeCII(Guid vesselId)
    {
        return _ciiAppService.CurrentYearCumulativeCII(vesselId);
    }

    /// <summary>
    /// CII 模拟器
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="targetCIIGrade"></param>
    /// <returns></returns>
    [Route("ExpectedPerformanceToMeetCIICurrentYear")]
    [HttpGet]
    public Task<CIIAndVDto> ExpectedPerformanceToMeetCIICurrentYear(Guid vesselId,
        [Required] CIIGrade targetCIIGrade)
    {
        return _ciiAppService.ExpectedPerformanceToMeetCIICurrentYear(vesselId, targetCIIGrade);
    }

    /// <summary>
    /// 目标航次预估 CII
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="targetDistance">目标航次的距离</param>
    /// <param name="hours">目标航次航行小时数</param>
    /// <returns></returns>
    [Route("EstimatedCIITargetVoyage")]
    [HttpGet]
    public Task<CIIAndVDto> EstimatedCIITargetVoyage(Guid vesselId, [Required] float targetDistance,
        [Required] float hours)
    {
        return _ciiAppService.EstimatedCIITargetVoyage(vesselId, targetDistance, hours);
    }

    /// <summary>
    /// 本年度累计 CO2 排放
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("CurrentYearCumulativeCo2Emissions")]
    [HttpGet]
    public Task<Co2EmissionsDto> CurrentYearCumulativeCo2EmissionsAsync(Guid vesselId)
    {
        return _ciiAppService.CurrentYearCumulativeCo2EmissionsAsync(vesselId);
    }
    
    /// <summary>
    /// 当前（年度）累计 CO2 排放量（已修正）
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("CurrentYearCumulativeCo2EmissionsAdjusted")]
    [HttpGet]
    public Task<Co2EmissionsDto> CurrentYearCumulativeCo2EmissionsAdjustedAsync(Guid vesselId)
    {
        return _ciiAppService.CurrentYearCumulativeCo2EmissionsAdjustedAsync(vesselId);
    }

    /// <summary>
    /// CII 营运碳强度对比
    /// </summary>
    /// <returns></returns>
    [Route("CIIOperationalCarbonIntensityComparison")]
    [HttpGet]
    public Task<CIIComparisionDto> CIIOperationalCarbonIntensityComparisonAsync(Guid vesselId,
        DateTime startDate, DateTime endDate)
    {
        return _ciiAppService.CIIOperationalCarbonIntensityComparisonAsync(vesselId, startDate, endDate);
    }

    /// <summary>
    /// CII 营运碳强度对比（范围为年）
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="year"></param>
    /// <returns></returns>
    [Route("CIIOperationalCarbonIntensityComparisonByYear")]
    [HttpGet]
    public Task<CIIComparisionDto> CIIOperationalCarbonIntensityComparisonByYearAsync(Guid vesselId, int year)
    {
        return _ciiAppService.CIIOperationalCarbonIntensityComparisonByYearAsync(vesselId, year);
    }

    /// <summary>
    /// 获取 CII 等级边界
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    [Route("CIIGradeBoundaries")]
    [HttpGet]
    public Task<CIIGradeBoundariesDto> CIIGradeBoundariesAsync(Guid vesselId)
    {
        return _ciiAppService.CIIGradeBoundariesAsync(vesselId);
    }
}